package com.kamikaze;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class Overtime_edit_do {
	String otd_date;
	String otd_time_begin ;
	String otd_time_end ;
	String ot_number;
	String otd_note ;
	
	
	public Overtime_edit_do() {
		super();
	}


	public String getOtd_date() {
		return otd_date;
	}


	public void setOtd_date(String otd_date) {
		this.otd_date = otd_date;
	}


	public String getOtd_time_begin() {
		return otd_time_begin;
	}


	public void setOtd_time_begin(String otd_time_begin) {
		this.otd_time_begin = otd_time_begin;
	}


	public String getOtd_time_end() {
		return otd_time_end;
	}


	public void setOtd_time_end(String otd_time_end) {
		this.otd_time_end = otd_time_end;
	}


	public String getOt_number() {
		return ot_number;
	}


	public void setOt_number(String ot_number) {
		this.ot_number = ot_number;
	}


	public String getOtd_note() {
		return otd_note;
	}


	public void setOtd_note(String otd_note) {
		this.otd_note = otd_note;
	}
	
	public boolean edit_overtime(String otd_date,
			String otd_time_begin ,String otd_time_end ,String ot_number,String otd_note,String otd_number )
	{
		boolean success=false;
		int ot_n = Integer.valueOf(ot_number);
		int otd_n = Integer.valueOf(otd_number);
		String update = "UPDATE  `j2`.`overtimedata` SET " +
				" `otd_date` =  ?,`otd_time_begin` =  ?,`otd_time_end` = ?,`ot_number` =  ?,`otd_note` =  ?" +
				" WHERE  `overtimedata`.`otd_number` =?";
		
			try {
				Class.forName("com.mysql.jdbc.Driver");
		Connection con = DriverManager
				.getConnection("jdbc:mysql://j.snpy.org/j2?user=team2&password=kamikaze&useUnicode=true&characterEncoding=UTF-8");
		PreparedStatement pstat = con.prepareStatement(update);
		pstat.setString(1, otd_date);
		pstat.setString(2, otd_time_begin);
		pstat.setString(3, otd_time_end);
		pstat.setInt(4, ot_n);
		pstat.setString(5, otd_note);
		pstat.setInt(6, otd_n);
		int row = pstat.executeUpdate();
		System.out.println("更動"+row+"筆資料");
		if(row==0){success=false;}
		pstat.close();
		con.close();
			} catch (ClassNotFoundException e) {e.printStackTrace();} 
			catch (SQLException e) {e.printStackTrace();}

		return success;
	}
	
	
}
